package network.tcp.tmp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-26 16:53
 **/
public class TcpClient {
    public static void main(String[] args) {
        client();
    }

    private static void client() {
        try (Socket client = new Socket("localhost", 9000);
             OutputStream o = client.getOutputStream();
             BufferedReader is = new BufferedReader(
                     new InputStreamReader(client.getInputStream()));
        ) {

            // SocketAddress bindpoint = new InetSocketAddress("localhost", 9000);
            //发送消息
            // client.bind(bindpoint);
            // client.connect(bindpoint);
            o.write("客户端发送消息了".getBytes());
            client.shutdownOutput();
            //接收消息
            String s;
            while ((s = is.readLine()) != null) {
                System.out.println(s);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }
}
